import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)

const store = new Vuex.Store({
    //放值
    state: {
        user: 0,
        userInfo:null,
        
    },
    //计算值
    getters: {
        // //可以对值进行公共计算
        // getterPrice(state) {
        //     // += 和 return += 会先执行
        //     return state.money + 20
        // }
    },
    //修改值
    mutations: {
        handlerUser(state, obj) {
            state.user = obj.userInfo.userId;
            state.userInfo = obj.userInfo
        },
        handlerUserId(state, obj) {
            state.user = obj.userId;
            state.userInfo=obj.userInfo
        }
    },
    actions: {

    },
    modules: {

    },
    //把数据存入localstorage
plugins:[createPersistedState()]
})

export default store